/**
 * 版权所有：厦门市巨龙信息科技有限公司
 * Copyright 2023 Xiamen Dragoninfo Eng. Co. Ltd.
 * All right reserved.
 */
package com.github.alfred.tool;

import org.redisson.api.RLock;

import java.util.concurrent.TimeUnit;

/**
 * Redisson分布式锁接口
 *
 * @author chengh
 * @date 2023/5/10 16:38
 */
public interface DistributedLocker {

    /**
     * 获取取锁
     * @param lockKey
     * @return
     */
    RLock lock(String lockKey);

    /**
     * 获取取锁 并设置超时时间
     * @param lockKey
     * @param timeout
     * @return
     */
    RLock lock(String lockKey, long timeout);

    /**
     * 获取取锁 并设置超时时间
     * @param lockKey
     * @param unit
     * @param timeout
     * @return
     */
    RLock lock(String lockKey, TimeUnit unit, long timeout);

    /**
     *  尝试获取锁
     * @param lockKey
     * @return
     */
    RLock tryLock(String lockKey);

    /**
     *   尝试获取锁
     * @param lockKey
     * @param unit
     * @param leaseTime
     * @return
     */
    boolean tryLock(String lockKey, TimeUnit unit, long leaseTime);

    /**
     * 尝试获取锁
     * @param lockKey
     * @param unit
     * @param waitTime
     * @param leaseTime
     * @return
     */
    boolean tryLock(String lockKey, TimeUnit unit, long waitTime, long leaseTime);

    /**
     * 解锁
     * @param lockKey
     */
    void unlock(String lockKey);

    /**
     * 解锁
     * @param lock
     */
    void unlock(RLock lock);


}
